package cn.com.shadowless.xinning.utils;

import android.app.Activity;
import android.app.ProgressDialog;

/**
 * The type Progress dialog utils.
 *
 * @author sHadowLess
 */
public class ProgressDialogUtils {
    /**
     * TODO 展示加载进度条
     *
     * @param dialogTitle Title 标题
     * @param dialogMessage Message 信息
     */
    private static ProgressDialog progressDialog = null;

    /**
     * 显示dialog方法
     *
     * @param context       the 上下文
     * @param dialogMessage the 提示信息
     */
    public static void showProgressDialog(Activity context, String dialogMessage) {
        showProgressDialog(context, null, dialogMessage);
    }

    /**
     * 显示dialog
     *
     * @param context       the 上下文
     * @param dialogTitle   the 标题
     * @param dialogMessage the 提示信息
     */
    public static void showProgressDialog(Activity context, String dialogTitle, String dialogMessage) {
        if (context == null) {
            return;
        }
        if (progressDialog == null) {
            progressDialog = new ProgressDialog(context);
        }
        if (progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
        if (dialogTitle != null && !"".equals(dialogTitle.trim())) {
            progressDialog.setTitle(dialogTitle);
        }
        if (dialogMessage != null && !"".equals(dialogMessage.trim())) {
            progressDialog.setMessage(dialogMessage);
        }
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.show();
    }

    /**
     * TODO 隐藏加载进度
     */
    public static void dismissProgressDialog() {
        if (progressDialog == null || !progressDialog.isShowing()) {
            return;
        }
        progressDialog.dismiss();
        progressDialog = null;
    }
}
